package com.cnc.servlet;

import com.cnc.service.Impl.StudentServiceImpl;
import com.cnc.service.StudentService;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/search")
public class SearchServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StudentService ss=new StudentServiceImpl();
        String name = req.getParameter("name");
        List<Object> list = ss.getStudentList(name);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(list);
        PrintWriter out = resp.getWriter();
        out.print(json);
        out.close();
    }
}
